<!DOCTYPE html>
<html>
<head>
   <!-- 页面meta -->
   <meta charset="utf-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <title>传智健康</title>
   <meta name="description" content="传智健康">
   <meta name="keywords" content="传智健康">
   <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
   <!-- 引入样式 -->
   <link rel="stylesheet" href="../plugins/elementui/index.css">
   <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
   <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
   <div class="content-header">
      <h1>会员管理
         <small>体检上传</small>
      </h1>
      <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
         <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
         <el-breadcrumb-item>会员管理</el-breadcrumb-item>
         <el-breadcrumb-item>体检上传</el-breadcrumb-item>
      </el-breadcrumb>
   </div>
   <div class="app-container">
      <div class="box">
         <!--搜索框-->
         <div class="filter-container">
            <el-input placeholder="档案号/姓名/手机号" v-model="pagination.queryString" style="width: 200px;"
                      class="filter-item"></el-input>
            <el-button @click="findPage()" class="dalfBut">查询</el-button>
         </div>
         <!--搜索框/-->

         <!--分页数据-->
         <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
            <el-table-column type="index" align="center" label="序号"></el-table-column>
            <el-table-column prop="regTime" label="体检时间" align="center"></el-table-column>
            <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
            <el-table-column prop="name" label="姓名" align="center"></el-table-column>
            <el-table-column prop="phoneNumber" label="手机号码" align="center"></el-table-column>
            <el-table-column prop="setmealName" label="检测套餐" align="center"></el-table-column>
            <el-table-column prop="orderStatus" label="报告状态" align="center"></el-table-column>
            <el-table-column label="操作" align="center">
               <template slot-scope="scope">
                  <el-button type="primary" size="mini" @click="handleUpload(scope.row)">上传</el-button>
                  <!--scope.row代表当前行的对象-->
                  <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
               </template>
            </el-table-column>
         </el-table>
         <!--分页数据/-->

         <!--分页条-->
         <div class="pagination-container">
            <el-pagination
               class="pagiantion"
               @current-change="handleCurrentChange"
               :current-page="pagination.currentPage"
               :page-size="pagination.pageSize"
               layout="total, prev, pager, next, jumper"
               :total="pagination.total">
            </el-pagination>
         </div>
         <!--分页条/-->

         <!-- 新增标签弹层 -->
         <div class="add-form"><!--v-if="dialogFormVisible" :visible.sync="dialogFormVisible"-->
            <el-dialog v-if="dialogFormVisible" :visible.sync="dialogFormVisible" title="上传体检文件">
               <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                  <el-row>
                     <el-col :span="12">
                        <el-form-item label="姓名">
                           <el-input :disabled="true" v-model="formData.name"/>
                        </el-form-item>
                     </el-col>
                  </el-row>
                  <el-row>
                     <el-col :span="12">
                        <el-form-item label="联系电话">
                           <el-input :disabled="true" v-model="formData.phoneNumber"/>
                        </el-form-item>
                     </el-col>
                  </el-row>
                  <el-row>
                     <el-col :span="12">
                        <el-form-item label="体检时间">
                           <el-input :disabled="true" v-model="formData.regTime"></el-input>
                        </el-form-item>
                     </el-col>
                  </el-row>
                  <el-row>
                     <el-col :span="24">
                        <el-form-item label="体检套餐">
                           <el-input :disabled="true" v-model="formData.setmealName"/>
                        </el-form-item>
                     </el-col>
                  </el-row>
                  <el-upload
                          class="upload-demo"
                          action="/member/upload.do"
                          :on-preview="handlePreview"
                          :on-remove="handleRemove"
                          :before-remove="beforeRemove"
                          multiple
                          :limit="1"
                          :on-exceed="handleExceed"
                          :file-list="fileList">
                     <el-button size="small" type="primary">点击上传</el-button>
                     <div slot="tip" class="el-upload__tip">上传会员体检报告文件，且不超过500kb</div>
                  </el-upload>
               </el-form>
               <div slot="footer" class="dialog-footer">
                  <!--<el-button @click="dialogFormVisible=false">取消</el-button>-->
                  <el-button @click="dialogFormVisible=false">取消</el-button>
                  <el-button type="primary" @click="handleUpdate()">确定</el-button>
               </div>
            </el-dialog>
         </div>

      </div>
   </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
   var app = new Vue({
      el: '#app',
      data: {
         showDialog: true, //弹框是否为新表单
         pagination: {//分页相关模型数据
            currentPage: 1,//当前页码
            pageSize: 10,//每页显示的记录数
            total: 0,//总记录数
            queryString: null//查询条件
         },
         dataList: [],//当前页要展示的分页列表数据
         formData: {},//表单数据
         fileList: [],//上传文件选中显示
         dialogFormVisible: false,//增加表单是否可见
         dialogFormVisible4Edit: false//编辑表单是否可见
      },

      //钩子函数，VUE对象初始化完成后自动执行,
      created() {
         //初始化分页查询
         this.findPage();
      },

      methods: {
         //分页查询
         findPage(isCustom) {
            //debugger;
            //0.判断是从查询按钮调用此方法
            if (!isCustom) {//无惨:默认重置当前页
               //将当前页码重置为1
               this.pagination.currentPage = 1;
            }
            //1.封装参数,当前页,每页尺寸,查询条件
            var para = {
               currentPage: this.pagination.currentPage,
               pageSize: this.pagination.pageSize,
               queryString: this.pagination.queryString
            };
            //2.发送ajax请求
            axios.post("/member/findPageBySC.do", para).then(res => {
               //获取返回结果{total:100,rows:[行数据]},赋值给分页模型
               this.pagination.total = res.data.total;
               this.dataList = res.data.rows;//赋值表数据
            }).finally();
         },

         //切换页码
         handleCurrentChange(currentPage) {
            //currentPage为新的当前页
            //1.修改当前页数据
            this.pagination.currentPage = currentPage;
            //2.调用分页查询方法
            this.findPage(1); //使用自定义当前页
         },

          //上传窗口显示，数据回显
          handleUpload(row){
            this.dialogFormVisible = true;
            this.formData = row;
          },
          //上传确定，更换信息
          handleUpdate(){
             //关闭窗口
              this.dialogFormVisible = false;
             //发送ajax请求，修改会员报告状态
              axios.post("/member/updateByType/"+this.formData.phoneNumber+".do").then((res) => {
                  if (res.data.flag){
                      this.$message({
                          message:res.data.message,
                          type:'success'
                      });
                  } else {
                      this.$message.error(res.data.message);
                  }
              }).finally(() => {//始终执行
                  this.findPage(1);//调用分页查询
              });
          },

         // 删除
         handleDelete(row) {
            //确认框
            this.$confirm('确认删除吗?', '提示', {
               confirmButtonText: '确定',
               cancelButtonText: '取消',
               type: 'warning'
            }).then(() => {//点确认,回调
               //发送ajax请求
               axios.delete("/member/delete/" + row.phoneNumber + ".do").then((res) => {
                  //判断是否删除成功
                  if (res.data.flag) {//删除成功
                     //成功框
                     app.$message({
                        message: res.data.message,
                        type: 'success'
                     });
                  } else {//删除失败
                     //失败框
                     this.$message.error(res.data.message);
                  }
               }).finally(() => {//始终执行
                  this.findPage(1);//调用分页查询
               });
            }).catch(() => {//点取消,回调
               //取消框
               this.$message({
                  type: 'info',
                  message: '已取消操作'
               });
            });
         },
          handleRemove(file, fileList) {
              console.log(file, fileList);
          },
          handlePreview(file) {
              console.log(file);
          },
          handleExceed(files, fileList) {
              this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
          },
          beforeRemove(file, fileList) {
              return this.$confirm(`确定移除 ${ file.name }？`);
          }
      }
   });
</script>

</html>